/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package verins.DAO;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

/**
 *
 * @author hectdx
 */
public class EstadoPadronDAO {
    
    
    public List findAllPadron(){
        List lista=null;
        
        try{
            
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("verinsPU");
            EntityManager em = emf.createEntityManager();
            
            Query query=em.createQuery("SELECT e FROM Estadopadron e WHERE e.nivel= 1 "
                    + "order by e.idestadopadron") ;
            lista=query.getResultList();
            em.close();    
            emf.close();
            
            return lista;
            
        }catch(Exception ex){
            System.out.println(lista!=null?lista.size():"-");
        }
        return lista;
    }

    public List findByDescripcion(String descripcion){
        List lista=null;

        try{

            EntityManagerFactory emf = Persistence.createEntityManagerFactory("verinsPU");
            EntityManager em = emf.createEntityManager();

            Query query=em.createQuery("SELECT e FROM Estadopadron e WHERE upper(e.descripcion) LIKE '%"+descripcion.toUpperCase()+"%'") ;
            lista=query.getResultList();
            em.close();
            emf.close();

            return lista;

        }catch(Exception ex){
            System.out.println(lista!=null?lista.size():"-");
        }
        return lista;
    }

    public List findAllPadronLinea(){
        List lista=null;
        
        try{
            
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("verinsPU");
            EntityManager em = emf.createEntityManager();
            
            Query query=em.createQuery("SELECT e FROM Estadopadron e WHERE e.nivel= 2 "
                    + "order by e.idestadopadron") ;
            lista=query.getResultList();
            em.close();    
            emf.close();
            
            return lista;
            
        }catch(Exception ex){
            System.out.println(lista!=null?lista.size():"-");
        }
        return lista;
    }
}
